package jalus.model;

import java.util.Date;
import java.util.List;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Text;
import com.google.appengine.api.users.User;
/**
 * 日志数据表
 * 
 *
 */
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable="true")
public class Post {
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Long id;
    
    @Persistent
    private String title;
    
    @Persistent
    private Date date;

    @Persistent
    private User author;

    @Persistent(defaultFetchGroup="true")
    private Text content;
    
    @Persistent
    private Integer privilege;
    
    @Persistent
    private Date last_modify_date;
    @Persistent
    private User last_modify_by;
    @Persistent
    private List<String> tags;

	private Integer commented;
	
	public Post(){}
    
    public Post(User author, String title, Integer privilege, Text content, Date date, List<String> tags) {
        this.author = author;
        this.title = title;
        this.privilege = privilege;
        this.content = content;
        this.date = date;
        this.tags = tags;
    }

    public Long getId() {
        return id;
    }

    public User getAuthor() {
        return author;
    }

    public Text getContent() {
        return content;
    }

    public Date getDate() {
        return date;
    }

    public void setId(Long id){
    	this.id = id;
    }
    
    public void setAuthor(User author) {
        this.author = author;
    }

    public void setContent(Text content) {
        this.content = content;
    }

    public void setDate(Date date) {
        this.date = date;
    }

	public void setTitle(String title) {
		this.title = title;
	}

	public String getTitle() {
		return title;
	}

	public void setPrivilege(int privilege) {
		this.privilege = privilege;
	}

	public int getPrivilege() {
		return privilege;
	}

	public void setLast_modify_date(Date last_modify_date) {
		this.last_modify_date = last_modify_date;
	}

	public Date getLast_modify_date() {
		return last_modify_date;
	}

	public void setLast_modify_by(User last_modify_by) {
		this.last_modify_by = last_modify_by;
	}

	public User getLast_modify_by() {
		return last_modify_by;
	}

	public void setTags(List<String> tags) {
		this.tags = tags;
	}

	public List<String> getTags() {
		return tags;
	}
	/**
	 * 是否在文章列表中显示
	 * @return
	 */
	public boolean isVisiable(){
		return this.privilege == 1 || this.privilege == 0;
	}
	/**
	 * 非管理员是否有权限查看
	 * @return
	 */
	public boolean isAuthorized(){
		return this.privilege == 1;
	}
	
	/**
	 * 是否开放评论
	 * @return
	 */
	public boolean isCommentEnabled(){
		return this.commented == 0 && this.privilege != 0;
	}
}